<?php

namespace app\index\model;

use think\Db;
use think\Model;

class Login extends Model
{
    public function login($data)
    {
        $res = Db::name('user')
            ->field(['pass', 'nickname', 'id', 'times'])
            ->where('tel', $data['tel'])
            ->find();

        if ($res) {
            if ($res['pass'] == MD5($data['pass'])) {
                return $res;
            } else {
                return false;
            }
        }
        return false;
    }

    public function uplogin($data, $id)
    {
        try {
            Db::name('user')->where('id', $id)->update($data);
        } catch (Exception $e) {
            $this->error('更新登录信息失败');
        }
    }

    public function mysql($data,$pwd)
    {
        $res = Db::name('user')
            ->field('nickname,pass,id,times')
            ->where('tel',$data)
            ->find();

        if ($res) {
            if ($res['pass'] == $pwd) {
                return $res;
            } else {
                return false;
            }
        }
        return false;
    }
}
